package com.hehe.conversion.hehemiddleware.common;

public class Result<R> {
    public Result(){
    }
    public Result(R r){
        this.status = StatusEnum.SUCCESS;
        this.returnObject = r;
    }

    public Result(String errorMessage, int errorCode){
        this.status = StatusEnum.ERROR;
        this.errorMessage = errorMessage;
        this.errorCode = errorCode;
    }

    private StatusEnum status;
    private R returnObject;
    private int errorCode;
    private String errorMessage;

    public boolean isOk(){
        return StatusEnum.SUCCESS.equals(this.getStatus());
    }

    public static <R> Result ok(R r) {
        Result<R> result = new Result(r);

        return result;
    }

    public static Result error(String msg){
        Result<String> result = new Result<>(msg, -1);

        return result;
    }
    public static  Result error(String msg, int errorCode){
        Result<String> result = new Result<String>(msg, errorCode);
        return result;
    }


    public StatusEnum getStatus() {
        return status;
    }

    public void setStatus(StatusEnum status) {
        this.status = status;
    }

    public R getReturnObject() {
        return returnObject;
    }

    public void setReturnObject(R returnObject) {
        this.returnObject = returnObject;
    }


    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
}
